package uml.behavioral.interpreter;

import uml.behavioral.interpreter.exception.IllegalInstructionException;

/**
 * 解释器--终结符表达式<br>
 * on 2022/12/31 0:27
 */
public class UnitNode extends AbstractNode {
    private String unit;

    public UnitNode(String unit) {
        this.unit = unit;
    }

    @Override
    public String interpret() throws IllegalInstructionException {
        switch (this.unit) {
            case "cm":
                return "厘米";
            case "dm":
                return "分米";
            case "m":
                return "米";
            case "km":
                return "千米";
            default:
                throw new IllegalInstructionException("无效指令");
        }
    }
}
